package com.ibeeking.found.cop.b.rest.service.mq;

import com.ibeeking.found.common.entity.MqMsgEventParam;
import com.ibeeking.found.cop.api.common.param.MsgEventFriendsParam;
import com.ibeeking.found.cop.b.rest.service.ICopDepartmentService;
import com.ibeeking.found.cop.b.rest.service.IFriendsTagsGroupService;
import com.ibeeking.found.cop.b.rest.service.IWxOpenService;
import com.ibeeking.nematos.log.utils.LogUtils;
import com.ibeeking.nematos.utils.data.StringUtils;
import com.ibeeking.nematos.utils.json.JsonUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class CopFriendsTagsMqMsgEventHandler {

    @Resource
    private IFriendsTagsGroupService friendsTagsGroupServiceImpl;

    @Resource
    private IWxOpenService wxOpenServiceImpl;

    public boolean addFriendsTagsMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> addFriendsTagsMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String id = friendsParam.getId();
            String tagType = friendsParam.getTagType();
            String strategyId = friendsParam.getStrategyId();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean updateFriendsTagsMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> updateFriendsTagsMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String id = friendsParam.getId();
            String tagType = friendsParam.getTagType();
            String strategyId = friendsParam.getStrategyId();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean deleteFriendsTagsMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> deleteFriendsTagsMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String id = friendsParam.getId();
            String tagType = friendsParam.getTagType();
            String strategyId = friendsParam.getStrategyId();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean shuffleFriendsTagsMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> shuffleFriendsTagsMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String id = friendsParam.getId();
            String strategyId = friendsParam.getStrategyId();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步信息任务处理异常:{}", e);
            return false;
        }
    }
}

